package com.jvm.interpreter.instruction;

import com.jvm.classfile.model.CpInfo;
import com.jvm.interpreter.Frame;
import com.jvm.interpreter.Instruction;

/**
 * @program: diy_simple_jvm
 * @description: iadd指令
 * @author: CaoYong
 * @create: 2021-07-08 13:48
 **/
public class IAddInst implements Instruction {


    /**
     * 将操作数栈栈顶的两个数相加并将结果推送到操作数栈栈顶
     * @param frame 栈帧
     */
    @Override
    public void eval(Frame frame) {
//        int v2 = frame.operandStack.pop();
//        int v1 = frame.operandStack.pop();
        int v2 = frame.popInt();
        int v1 = frame.popInt();
//        frame.operandStack.push(v1 + v2);
        frame.pushInt(v1 + v2);

        frame.pc += offset();
    }

    static IAddInst parse(java.io.DataInputStream dis, CpInfo[] cp) throws java.io.IOException {
        return new IAddInst();
    }
}
